﻿using EMoney.IStock.Client.Framework;
using EMoney.IStock.Client.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EMoney.IStock.Client.Business.MC
{
    public class WebApiBll
    {
        /// <summary>
        /// 判断账号是否存在
        /// </summary>
        /// <param name="account"></param>
        /// <param name="type">1:手机 2:邮箱</param>
        /// <returns></returns>
        public static bool IsExistUser(string account,string type)
        {
            bool flag = false;
            string url = string.Concat(ConfigHelper.WebAPIUrl, "/User/api/IStock.IsExistUser?appId=", ConfigHelper.UserAppId, "&username=", account, "&type=", type, "&retid=1");

            url = WebApiHelper.CreateUrl(url, ConfigHelper.UserWebApiKey);

            NetHelper net = new NetHelper();

            string result = net.GetClientBySocket(url);

            if (!string.IsNullOrEmpty(url))
            {
                try
                {
                    WebApiExistUserRet ret = JsonHelper.ToObject<WebApiExistUserRet>(result);

                    if (ret != null && ret.RetMsg == "账号已被注册")
                    {
                        flag = true;
                    }
                }
                catch (Exception ex)
                {
                    LogManager.DefaultLogger.Error(ex, string.Concat("判断账号是否存在失败.", account));
                }
            }

            return flag;
        }
    }
}
